23 template <class T
> string
toStr(const T
&x
) { stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
) { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
28 #define D(x) cout << #x " = " << (x) << endl
30 const double EPS
= 1e-10;
32 int cmp(double x
, double y
= 0, double tol
= EPS
){
33 return( x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
38 point(){} point(double x
, double y
, double z
) : x(x
), y(y
), z(z
) {}
44 inline double dist(const point
&a
, const point
&b
) {
45 double dx
= b
.x
- a
.x
, dy
= b
.y
- a
.y
, dz
= b
.z
- a
.z
;
46 return sqrt(dx
* dx
+ dy
* dy
+ dz
* dz
);
49 point
positionAt(int p
, double t
) {
50 double d
= V
[p
] * t
, s
= 0.0;
51 for (int i
= 0; i
< P
[p
].size() - 1; ++i
) {
52 double distance
= dist(P
[p
][i
], P
[p
][i
+1]);
53 if (cmp(s
+ distance
, d
) < 0) {
57 double dx
= P
[p
][i
+1].x
- P
[p
][i
].x
;
58 double dy
= P
[p
][i
+1].y
- P
[p
][i
].y
;
59 double dz
= P
[p
][i
+1].z
- P
[p
][i
].z
;
60 ans
.x
+= (d
- s
) * dx
/ distance
;
61 ans
.y
+= (d
- s
) * dy
/ distance
;
62 ans
.z
+= (d
- s
) * dz
/ distance
;
64 assert(cmp(s
+ dist(P
[p
][i
], ans
), d
) == 0);
72 int casos
; scanf("%d", &casos
); while (casos
--) {
73 for (int p
= 0; p
< 2; ++p
) {
74 int k
; scanf("%d %d %d", &R
[p
], &V
[p
], &k
);
76 for (int i
= 0; i
< k
; ++i
) {
77 scanf("%lf %lf %lf", &P
[p
][i
].x
, &P
[p
][i
].y
, &P
[p
][i
].z
);
79 P
[p
].push_back( point(0, 0, 0) );
82 double totalTime
= 1e100
;
83 for (int p
= 0; p
< 2; ++p
) {
85 for (int i
= 0; i
< P
[p
].size() - 1; ++i
) {
86 d
+= dist(P
[p
][i
], P
[p
][i
+1]);
88 totalTime
= min(totalTime
, d
/ V
[p
]);
91 int iterations
= 9500;
92 double delta
= totalTime
/ iterations
;
93 // point p1 = positionAt(0, totalTime);
94 // point p2 = positionAt(1, totalTime);
95 // printf("<%lf, %lf, %lf>\n", p1.x, p1.y, p1.z);
96 // printf("<%lf, %lf, %lf>\n", p2.x, p2.y, p2.z);
99 for (int i
= 0; i
<= iterations
; ++i
) {
100 double distance
= dist(positionAt(0, i
* delta
), positionAt(1, i
* delta
));
101 if (cmp(distance
, 1.0 * (R
[0] + R
[1])) <= 0) {